package com.damn;
import com.google.code.facebookapi.*;
import com.google.code.*;

public class FBClient {
	public String CreateFBClient()
	{
	FacebookJsonRestClient client =       new FacebookJsonRestClient(API_KEY, SECRET);
    client.setIsDesktop(true); // is this a desktop app

    try {
      String token = client.auth_createToken();
      // Build the authentication URL for the user to fill out
      String url = “http://www.facebook.com/login.php?api_key=” 
                + API_KEY + “&v=1.0″ 
                + “&auth_token=” + token;
      // Open an external browser to login to your application
      Runtime.getRuntime().exec(“open ” + url); // OS X only!
      // Wait until the login process is completed
      System.out.println(“Use browser to login then press return”);
      System.in.read();

      // fetch session key
      String session = client.auth_getSession(token,true ); 
// obtain temp secret
String tempSecret = client.getSessionSecret();
// new facebook client object
client = new FacebookJaxbRestClient(API_KEY, tempSecret, sessionKey);

      System.out.println(“Session key is ” + session);

      // keep track of the logged in user id
      Long userId = client.users_getLoggedInUser(); 
      System.out.println(“Fetching friends for user ” + userId);

      // Get friends list
      client.friends_get();
      FriendsGetResponse response = (FriendsGetResponse) client.getResponsePOJO();
      List<Long> friends = response.getUid();

      // Go fetch the information for the user list of user ids
client.users_getInfo(friends, EnumSet.of(ProfileField.NAME));

UsersGetInfoResponse userResponse = (UsersGetInfoResponse) client.getRepsonsePOJO();
      // Print out the user information
      List<User> users = userResponse.getUser();
      for (User user : users) {
        System.out.println(user.getName());
      }
    } catch (FacebookException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return "Success";
    
	}

}
